package rwt.server.handlers;

import org.slf4j.*;

import rwt.server.RailServer;
import rwt.server.RailroadMessages.PutReadLayoutResponseMsg;
import rwt.server.core.*;

public class PutReadLayoutResponseHandler extends MessageHandler<PutReadLayoutResponseMsg>
{
	private static final Logger logger = LoggerFactory.getLogger(PutReadLayoutResponseHandler.class);
	
	@Override
	public void handle(PutReadLayoutResponseMsg message, IConnection source) throws Exception
	{
		if (message.responseFlag == 1 && message.code == 0)
		{
			// Success!
			logger.info("Layout response: Success");
			
			//Wait then get switches from controller
			Thread.sleep(1000);
			RailServer.getSwitchManager().getSwitchStates();
		}
		else
		{
			logger.warn("Layout response: Failed [flag: {}, code: {}]", message.responseFlag,
					message.code);
		}
	}
}
